package types;

import java.util.ArrayList;

public class Tree {
	 
	ArrayList<SubSet> list = new ArrayList<SubSet>();

	//constructor
    public Tree () { 
    	SubSet s0 = new SubSet();
    	SubSet s1 = new SubSet();
    	
    	s0.setElement("0");
    	s1.setElement("root");

    	list.add(s0);	// 0
    	list.add(s1);	// root
    } 
    
    public boolean empty () { 
        return list.isEmpty();
    } 
    
    public int left (int i) {  return 2*i;  } 
    public int right (int i) {  return 2*i + 1;  } 
    public int parent (int i) {  return i/2;  } 
    
    
    // getters and setters
    public SubSet getCargo (int i) { 
    	if (i < 0 || i >= list.size()) return null; 
        return list.get(i); 
    } 
    
    public ArrayList<SubSet> getTree () { 
    	return list;
    } 
    
    public int getTreeSize () {  
    	return list.size();
    } 

    public void setCargo (int i, SubSet subset1) { 
    	if (i < 0 || subset1==null) return; 
    	list.add(i,subset1);
    } 
    
    public void setNullCargo (int i) {  
    	SubSet s1 = new SubSet();
		s1.setElement("null");
    	list.set(i, s1);
    } 
    
    public void addNullCargo (int i) {  
    	SubSet s1 = new SubSet();
		s1.setElement("null");
    	list.add(i, s1);
    } 
    
    public int getNodeLevel(int i)
    {	
    	int level = (int)(Math.pow(2, i));
    	return level;
    }
    

}
